//电影管理
var express = require('express');
var router = express.Router();
var sqlQuery = require('../../../module/sql');
var jiami = require('../../../module/jiami');



router.get('/', function(req, res, next) {
  res.render('admin/film/filmlist')

});



//获取所有电影数据

router.get('/api',async(req,res)=>{
  let page = parseInt(req.query.page);  //第几页
  let limitNum = parseInt(req.query.limit); //限制多少条
  // let sqlStr = 'select `film`.id,`film`.filmName,`film`.state,`film`.hot,film`.region,type.typeName from film LEFT JOIN type on `film`.Typeid=type.id limit ?,?'
  let sqlStr = 'SELECT film.id,film.filmName,film.state,film.hot,type.typeName,user.username FROM film,type,user WHERE film.Typeid = type.id AND film.userid=user.id LIMIT ?,?'
  let arr = [(page-1)*limitNum,limitNum]
  let result = await sqlQuery(sqlStr,arr);
  //获取电影的总数
  let sqlStr1 = "select count(id) as number from film"
  let result1 = await sqlQuery(sqlStr1)
  let count = result1[0].number
  let options ={
    "code": 0,
    "msg": "",
    "count": count,
    "data": Array.from(result)
  }
  res.json(options)
})



module.exports = router;
